﻿using SQLite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SMARTMobile.Data 
{
    public class ConnectionStringInfo
    {
        public SQLiteConnection GetConnectionStringInfo()
        {
            SQLiteConnection db = null;
            string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Distributor.db");
            if (FileExists("db.sqlite").Result)
            {
                db = new SQLiteConnection(dbPath);
            }

            return db;
        }

        public SQLiteAsyncConnection GetAsyncConnectionInfo()
        {
            SQLiteAsyncConnection db = null;
            string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Distributor.db");
            db = new SQLiteAsyncConnection(dbPath);

            return db;
        }

        private async Task<bool> FileExists(string databaseFullPath)
        {
            var result = false;
            try
            {
                var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("Distributor.db");
                result = true;
            }
            catch
            {
            }

            return result;
        }         
    }
}
